#########################################################

work_dir=/public/home/xxf2019/20220915_gastric_multiple/dna_batch_raw
config_path=/public/home/xxf2019/20220915_gastric_multiple/dna_batch_raw/config

mkdir -p ${config_path}

#########################################################
## 产生patient_list
echo "sample,seq_Type" > ${config_path}/patients.csv

cat ${work_dir}/tumor_normal.raw.list | sed '1d' | awk -F'\t' '{print $1}' | sort -u | \
awk '{OFS=","}{print $1,"WES"}' >> ${config_path}/patients.csv

cat ${work_dir}/tumor_normal.raw.list | sed '1d' | awk -F'\t' '{print $2}' | sort -u | \
awk '{OFS=","}{print $1,"WES"}' >> ${config_path}/patients.csv

#########################################################
## Tumor_Normal
echo "Tumor,Normal,seq_type" > ${config_path}/tumor_normal.list

cat ${work_dir}/tumor_normal.raw.list | sed '1d' | tr '\t' ',' | sort -u | \
awk -F, '{OFS=","}{print $2,$1,"WES"}' >> ${config_path}/tumor_normal.list

## Normal list
echo "Normal,seq_type" > ${config_path}/normal.list 
cat ${work_dir}/tumor_normal.raw.list | sed '1d' | awk -F'\t' '{print $1}' | sort -u | \
awk '{OFS=","}{print $1,"WES"}' | sort -u >> ${config_path}/normal.list 

#########################################################
## 捕获区域
cp -rf ~/20220915_gastric_multiple/config/Target* ${config_path}

#########################################################
## Bam_QC
work_dir=/public/home/xxf2019/20220915_gastric_multiple/dna_batch_raw
cd ~/20201204_NextFlowTest_FastqToBam

inputdir=${work_dir}/bam
genome=grch37
seq_type=WGS
genomicsdb=""
use_genomicdb=""

start=bamqc
sh WorkFlow.sh ${inputdir} ${work_dir} ${start} ${genome} ${genomicsdb} ${use_genomicdb} ${seq_type}

################################################################## 
## call somatic的突变
cd ~/20210318_NextFlow_somatic_v1

work_dir=/public/home/xxf2019/20220915_gastric_multiple/dna_batch_raw/somatic
inputdir=/public/home/xxf2019/20220915_gastric_multiple/dna_batch_raw/bam
seq_Type=WES
genome=grch37
sh WorkFlow_all.sh ${work_dir} ${inputdir} ${seq_Type} ${genome}

################################################################## 
## Somatic和质控放一个文件夹
mv /public/home/xxf2019/20220915_gastric_multiple/dna_batch_raw/somatic \
/public/home/xxf2019/20220915_gastric_multiple/dna_batch_raw/results

#########################################################
## TITANCNV
cd ~/20210318_NextFlow_somatic

work_dir=/public/home/xxf2019/20220915_gastric_multiple/dna_batch_raw
start=titanCNA
inputdir=${work_dir}/results/bam
seq_type=WES
genome=grch37

sh DNA-Seq-Somatic.sh --outdir ${work_dir}/results --design ${work_dir}/config/tumor_normal.list --normal \
${work_dir}/config/normal.list -profile babs \
--inputdir ${inputdir} --start ${start} --pon ${work_dir}/results/vcf/pon.vcf.gz --seq_type ${seq_type} \
--genome ${genome} -resume

################################################################## 
## call gemrline的突变,后续用于判断亲缘系数
cd ~/20210409_NextFlow_GRCh37

work_dir=/public/home/xxf2019/20220915_gastric_multiple/dna_batch_raw
inputdir=/public/home/xxf2019/20220915_gastric_multiple/dna_batch_raw/bam
seq_Type=WES
start=haplotypeCaller
depth=low

sh FastqToBam_grch37.sh --outdir ${work_dir}/results --design ${work_dir}/config/patients.csv --inputdir ${inputdir} \
--start ${start} --genome grch37 --depth ${depth} -profile babs -resume

